Ext.define('component.phone.calltWindow', {
	extend : 'Ext.window.Window',
	callbackFun: function (uniqueId) {
		Ext.Msg.alert('提示', '回调函数未配置！');
	},
	config:{ 
		//被叫号码
		caller: '',
		terminalModel:'',
		terminalModelId:'',
		contextPath:'',
		projectId:'',
		projectId:'',
		relationId:'',
		relationType:'',
		callPhoneUrl:'/phone/dial/call'
	},
	initRadioGroup:function(){
		var me=this;
		var contextPath=this.contextPath; 
		var formPanel=Ext.create("Ext.form.Panel",{
			id:"window_form_papel"
		});
		Ext.Ajax.request({
				url: contextPath+'/system/user/findUserPhone',
				params:{},
				method:'POST', 
				callback: function (options, success, response) {
					 if (success) {
						 var obj = JSON.parse(response.responseText);
						 if(obj.res=="1"){
							 var calledArray=Ext.decode(obj.obj);
							 Ext.Array.every(calledArray,function(rowCalled,index,array){ //返回false 立即返回  
								    var type=rowCalled.type;
								    var phone=rowCalled.phone;
								    var showPhone="";
								    if(type=="1"){
								    	showPhone="手机【"+phone+"】";
								    }else{
								    	showPhone="固话【"+phone+"】";
								    }
									var rowCalledRadio=Ext.create("Ext.form.field.Radio",{ boxLabel: showPhone, name: 'called', inputValue: phone});
									formPanel.add(rowCalledRadio);
									return true;
							 });
							 me.add(formPanel);
							 me.show();
						 }else{
							Ext.MessageBox.alert("系统提示",obj.resMsg); 
						 }
		        	 }else{
		        		 Ext.MessageBox.alert("系统提示","系统异常!");
		        	 }
				}
				
		});
		
		
		
	},
	initComponent : function() {
		var me=this;
		var caller=this.caller;
		var terminalModel=this.terminalModel;
		var terminalModelId=this.terminalModelId;
		var contextPath=this.contextPath; 
		var projectId = this.projectId;
		var relationId = this.relationId;
		var relationType = this.relationType;
		var callPhoneUrl = this.callPhoneUrl;
		var defaultConfig = {
				frame:true,
				modal : true, 
				buttonAlign:'center',
				title : '选择拨打号码',
				width : 350,
                buttons:[{
          	      xtype: "button",
                  text: "确定",
                  iconCls:'icon-save',
                  handler: function(){
                	  var calledValue = Ext.getCmp("window_form_papel").getForm().findField("called").getGroupValue(); 
                	  if(null==calledValue || calledValue==""){
                		  Ext.MessageBox.alert("系统提示","请选择主叫号码！"); 
                		  return;
                	  }
                	  
                	  if(null==terminalModel || terminalModel==""){
                		  Ext.MessageBox.alert("系统提示","组件调用参数错误！"); 
                		  return;
                	  }
                	  if(null==terminalModelId || terminalModelId==""){
                		  Ext.MessageBox.alert("系统提示","组件调用参数错误！"); 
                		  return;
                	  }
                	  Ext.Ajax.request({
          				url: contextPath+callPhoneUrl,
          				params:{
          					caller:calledValue,
          					called:caller,
          					terminalModel:terminalModel,
          					terminalModelId:terminalModelId,
          					projectId:projectId,
          					relationId:relationId,
          					relationType:relationType
          				},
          				method:'POST', 
          				callback: function (options, success, response) {
          					 if (success) {
          						 var obj = JSON.parse(response.responseText);
          						 if(obj.res=="1"){
          							var uniqueId=obj.obj;
          							me.close();
          							me.callbackFun(uniqueId);
          						 }else{
          							Ext.MessageBox.alert("系统提示",obj.resMsg); 
          						 }
          		        	 }else{
          		        		 Ext.MessageBox.alert("系统提示","系统异常!");
          		        	 }
          				}
          				
          		});
                  }},{
          	      xtype: "button",
                  text: "取消",
                  iconCls:'icon-save',
                  handler: function(){
                	  me.close(); 
                  }
                }]
		};
		Ext.apply(this,defaultConfig);
		this.callParent();
	}
});
